import { define } from 'cydon'
import { EditableTable } from './EditableTable'
import { onHashChange } from '../utils'

@define('manage-tag')
export class ManageTag extends EditableTable {
	connectedCallback() {
		const { hash } = location
		onHashChange(name => {
			if (location.hash != hash) // FIXME
				location.reload()
			const { data } = this
			switch (name) {
				case 'alias':
					data.objectName = 'TagAlias'
					data.keys = ',id,name,alias,desc,creator,created_at'.split(',')
					data.columns = ',ID,名称,别名,描述,创建者,创建时间'.split(',')
					data.newItemJSON = '{"id":0,"name":"","alias":"","desc":""}'
					break
				case 'category':
					data.objectName = 'TagCategory'
					data.keys = ',name,parent,desc,style,creator,created_at'.split(',')
					data.columns = ',名称,父分类,描述,样式,创建者,创建时间'.split(',')
					data.newItemJSON = '{"name":"","parent":"","desc":"","style":""}'
					break
				case 'implications':
					data.objectName = 'Implication'
					data.keys = ',id,antecedent,consequent,creator,created_at'.split(',')
					data.columns = ',ID,标签,隐含的标签,创建者,创建时间'.split(',')
					data.newItemJSON = '{"id":0,"antecedent":"","consequent":""}'
					break
				case 'group':
					data.objectName = 'TagGroup'
					data.keys = ',id,name,desc,creator,created_at'.split(',')
					data.columns = ',ID,名称,描述,创建者,创建时间'.split(',')
					data.newItemJSON = '{"id":0,"name":"","desc":""}'
					break
				default:
					data.objectName = 'Tag'
					data.keys = ',id,name,category,group,count,creator,created_at,updated_at'.split(',')
					data.columns = ',ID,名称,类别,互斥组,使用计数,创建者,创建时间,更新时间'.split(',')
					data.newItemJSON = '{"id":0,"name":"","category":"","group":""}'
			}
		})
		super.connectedCallback()
	}
}